#!/usr/bin/python


import web
import netsnmp
import multicore

from web.contrib.auth import dbauth, views
render = web.template.render('templates/')
import sys

urls = (
    '/', 'index',
    '/add','add',
    '/sysname','getsysname'
)


app = web.application(urls, globals(),autoreload=False)
db = web.database(dbn="sqlite", db="db/pyBayTech.db")
settings = {}
auth = dbauth.DBAuth(app, db, **settings)
data = {}




try:
   perms=['admin']
   auth.createUser('admin', 'admin@pass',perms,**data)
   perms=['user']
   auth.createUser('user', 'user@pass',perms,**data)
except Exception as AuthError:
   print "Unexpected error:", sys.exc_info()[0]


print data.items
   
class index:
    @auth.protected()
    def GET(self):
        outlets = db.select('outlets')
        return render.index(outlets)

class add:
   def POST(self):
        i = web.input()
        n = db.insert('outlets', name=i.name)
        raise web.seeother('/index')

class getsysname:
	def GET(self):
		oid = 'sysName.0'
      
		res = netsnmp.snmpget(oid, Version = 2, DestHost = '74.252.112.28', Community='public')
      foo = netsnmp.snmpset()
      
      print res
		return render.getsysname(res)
		
class controloutlet:
   def POST(self):
   
      login = form.Form(
      form.Textbox('username'),
      form.Password('password'),
      form.Button('Login'),
      )
     
		
if __name__ == "__main__": app.run()

